package com.ymttest.business.data;

import java.io.IOException;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

import org.apache.http.client.ClientProtocolException;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import org.junit.runner.Result;

import com.google.gson.JsonObject;
import com.ymatou.iapi.userregister.parameter.UserRegisterInfoRequestDtoBean;
import com.ymatou.iapi.userregister.service.UserRegisterInfoRequestDtoCall;
import com.ymatou.iapi.userservice.parameter.AddressRequestDtoBean;
import com.ymt.base.YmatouBaseCall;
import com.ymt.base.YmatouEasyCall;
import com.ymt.core.tool.FormatUtil;
import com.ymt.core.tool.Logger;
import com.ymttest.business.service.AccountCallService;
import com.ymttest.business.service.AuthCallService;
import com.ymttest.business.service.JUserCallService;
import com.ymttest.utils.TestDataManager;

public class CreateUser {

	public static void main(String[] args) throws JSONException, ClientProtocolException, IOException, InterruptedException {
		ExecutorService SERVICE = Executors.newFixedThreadPool(20);
		for (int i = 0; i < 1; i++) {
			SERVICE.execute(() -> {
				UserRegisterInfoRequestDtoBean regbean;
				try {
					// 注册用户
					regbean = JUserCallService.initUserRegisterInfoRequestDtoBean();
					UserRegisterInfoRequestDtoCall urrc = JUserCallService.UserRegisterInfoRequestDtoCall(regbean);
					JsonObject result = urrc.getJsonObject().get("Result").getAsJsonObject();
					String token = result.get("Token").getAsString();
					Integer uid = result.get("UserId").getAsInt();
					// 更新支付密码
					JUserCallService.UpdateTradingPwd(uid, "abc123");
					// 创建资金账户并充值
					String aid = AccountCallService.getAccountId(uid);
					AccountCallService.resetAccount(aid, new BigDecimal(99999), new BigDecimal(0));
					AddressRequestDtoBean addressBean = JUserCallService.initAddressBean(uid);
					JUserCallService.AddressRequestDtoCall(addressBean);
					TestDataManager.appendFileToLine("newToken.txt", token + "," + uid);
				} catch (Exception e) {
					e.printStackTrace();
				}
			});
		}
		SERVICE.shutdown();
		while (!SERVICE.isTerminated()) {
			Logger.debug("not isTerminated");
			try {
				Thread.sleep(1000);
			} catch (InterruptedException e) {
				e.printStackTrace();
			}
		}
		Logger.debug("isTerminated");
	}
}
